/* eslint valid-jsdoc: "off" */

'use strict';
// const path = require('path');
/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {
    // use for cookie sign key, should change to your own and keep security
    keys: appInfo.name + '_1589506901350_7071',
    // add your middleware config here
    // middleware: [
    //   'graphql',
    // ],
    ossUrl: {
      // 获取验证码
      sendVerify: 'https://service.zeroccharge.com/iot_device/sms/send/verify',
      // 上传文件
      ossUpload: 'https://service.zeroccharge.com/iot_device/oss/upload/thu-ee-design/prod',
    },
    multipart: {
      // mode: 'file',
      fileExtensions: [
        // '.pdf',
        // '.doc',
        // '.docx',
        // '.ppt',
        // '.pptx',
        // '.rar',
        // '.mov',
        // '.m4v',
        '.xlsx',
        '.xls',
        '.SchDoc',
      ],
      fileSize: '50mb',
    },
    session: {
      key: 'sess',
      maxAge: 15 * 24 * 3600 * 1000, // 15 天
      httpOnly: true,
      encrypt: true,
      renew: true,
    },
    // https://eggjs.org/zh-cn/core/security.html#安全威胁csrf的防范
    security: {
      csrf: {
        enable: false,
      },
      // domainWhiteList: [
      //   'http://localhost:5173',
      // ],
    },
    // graphql: {
    //   router: '/graphql',
    // },]
    sequelize: {
      datasources: [
        // localhost 本地数据库
        {
          delegate: 'model',
          baseDir: 'model',
          dialect: 'mysql',
          host: '127.0.0.1',
          port: 3306,
          database: 'test-file',
          username: 'root',
          password: '',
          define: {
            underscoredAll: true,
          },
          pool: {
            max: 3, // Maximum number of connection in pool
            min: 1, // Minimum number of connection in pool
            acquire: 20000, // The maximum time, in milliseconds, that pool will try to get connection before throwing error
            idle: 10000, // The maximum time, in milliseconds, that a connection can be idle before being released
          },
          timezone: '+08:00',
        },
      ],
    },
    cors: {
      origin(ctx) {
        return ctx.request.header.origin;
        // if (/(http[s]?:\/\/localhost:5173$)/.test(ctx.request.header.origin)) {
        //   return ctx.request.header.origin;
        // }
      },
      maxAge: 3600,
      allowMethods: [ 'GET', 'POST' ],
      credentials: true,
    },
    // logger: {
    //   // dir: './logs',
    //   dir: path.join(appInfo.baseDir, 'logs'),
    //   // dir: path.resolve(__dirname, '../', 'web/logs/oms-api'),
    // },
  };

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  return {
    ...config,
    ...userConfig,
  };
};
